package com.yuqiao.read.design.iterator;

import java.util.Iterator;

public class DinerMenu implements Menu{


    static final int MAX_ITEMS = 9;
    int numberOfItems = 0;
    MenuItem [] menuItems;
    public DinerMenu(){
        menuItems = new MenuItem[MAX_ITEMS];
        addItem("x","xxx",true,11.2);
        addItem("y","yyy",true,51.2);
        addItem("n","nnn",false,61.2);
        addItem("xc","sadf",true,61.2);
        addItem("ig","gjkf",true,671.2);
        addItem("afdsg","fasfe",true,41.2);
        addItem("hhh","xxxgdf",true,41.2);
    }

    public void addItem(String name,String description,boolean vegetarian,double price){
        MenuItem menuItem = new MenuItem(name,description,vegetarian,price);
        if(numberOfItems>=MAX_ITEMS){
            System.err.println("对不起，菜单已经满了");
        }else{
            menuItems[numberOfItems] = menuItem;
            numberOfItems = numberOfItems + 1;
        }
    }

//    public MenuItem[] getMenuItems() {
//        return menuItems;
//    }
    @Override
    public Iterator createIterator(){
        return new DinerMenuIterotor(menuItems);
    }
}
